package com.ruoyi.web.controller.system.carPack;

import java.util.List;

import com.ruoyi.common.config.HeadNum;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.GetSessionValueUtil;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.system.domain.SysUser;
import com.ruoyi.system.domain.carPark.FzCarPark;
import com.ruoyi.system.domain.communiry.FzSCommunity;
import com.ruoyi.system.service.carPark.IFzCarParkService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpSession;

/**
 * 停车场管理
Controller
 * 
 * @author ruoyi
 * @date 2020-03-03
 */
@Controller
@RequestMapping("/system/park")
public class FzCarParkController extends BaseController
{
    private String prefix = "system/carPark/park";

    @Autowired
    private IFzCarParkService fzCarParkService;

    @RequiresPermissions("system:park:view")
    @GetMapping()
    public String park()
    {
        return prefix + "/park";
    }

    /**
     * 查询停车场管理
列表
     */
    @RequiresPermissions("system:park:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HttpSession session,FzCarPark fzCarPark)
    {
        startPage();
        String communityId=((FzSCommunity)session.getAttribute("ycommunity")).getCommunityId();
        fzCarPark.setcId(communityId);
        List<FzCarPark> list = fzCarParkService.selectFzCarParkList(fzCarPark);
        return getDataTable(list);
    }

    /**
     * 导出停车场管理
列表
     */
    @RequiresPermissions("system:park:export")
    @Log(title = "停车场管理 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FzCarPark fzCarPark)
    {
        List<FzCarPark> list = fzCarParkService.selectFzCarParkList(fzCarPark);
        ExcelUtil<FzCarPark> util = new ExcelUtil<FzCarPark>(FzCarPark.class);
        return util.exportExcel(list, "park");
    }

    /**
     * 新增停车场管理

     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存停车场管理

     */
    @RequiresPermissions("system:park:add")
    @Log(title = "停车场管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FzCarPark fzCarPark)
    {
        fzCarPark.setCarParkId(HeadNum.CAR_PARK_HEAD+ DateUtils.getTimeMillis());
      fzCarPark.setcId(GetSessionValueUtil.getCommunity());
        SysUser user = ShiroUtils.getSysUser();
        fzCarPark.setCreateName(user.getUserName());
        return toAjax(fzCarParkService.insertFzCarPark(fzCarPark));
    }

    /**
     * 修改停车场管理

     */
    @GetMapping("/edit/{carParkId}")
    public String edit(@PathVariable("carParkId") String carParkId, ModelMap mmap)
    {
        FzCarPark fzCarPark = fzCarParkService.selectFzCarParkById(carParkId);
        mmap.put("fzCarPark", fzCarPark);
        return prefix + "/edit";
    }

    /**
     * 修改保存停车场管理

     */
    @RequiresPermissions("system:park:edit")
    @Log(title = "停车场管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FzCarPark fzCarPark)
    {
        SysUser user = ShiroUtils.getSysUser();
        fzCarPark.setUpdateName(user.getUserName());
        return toAjax(fzCarParkService.updateFzCarPark(fzCarPark));
    }

    /**
     * 删除停车场管理

     */
    @RequiresPermissions("system:park:remove")
    @Log(title = "停车场管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fzCarParkService.deleteFzCarParkByIds(ids));
    }
}
